#ifndef __HEAD_H__
#define __HEAD_H__

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <signal.h>  
#include <sys/wait.h>   


#define ERROR_CHECK(ret, retval, msg) \
    do { \
        if ((ret) == (retval)) { \
            perror(msg); \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

// 参数个数检查宏：如果argc不等于expected，就提示用法并退出
#define ARGS_CHECK(argc, expected) \
    do { \
        if ((argc) != (expected)) { \
            fprintf(stderr, "Usage: %s [args...]\n", argv[0]); \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

#endif // __HEAD_H__

enum {
    FREE,
    BUSY
};
//#define FREE 0;
//#define BUSY 1
typedef struct workerdata_s {//worker（子进程）信息结构体
    pid_t pid;
    int status;
    int pipesockfd; // 父进程和子进程通信用的socketpair的fd
}workerdata_t;


int makeWorker(int workerNum, workerdata_t * workerArr);
int tcpInit(const char *ip, const char *port, int *psockfd);
int epollAdd(int epfd, int fd);
int epollDel(int epfd, int fd);
int sendfd(int sockfd, int fdtosend, int exieFlag);
int recvfd(int sockfd, int *pfdtorecv, int *pexitFlag);
int workLoop(int sockfd);
int transFile(int netfd);